<?php
namespace Admin\Controller;
use Think\Controller;
use Think\Verify;
use Think\Model\RoleModel;
class RoleController extends Controller {
    public function showlist(){
        $roles = D('Role')->select();
        $this->assign('role',$roles);
        //dump($roles);
        $this->display();
    }
    public function distribute($roleid){
        $role = new \Model\RoleModel();
        if(!empty($_POST)){
            //dump($_POST);
            $z = $role->saveAuth($roleid,$_POST['auth_id']);
            if($z){
                $this-redirect('showlist',array(),2,'分配权限成功');
            } else {
                $this-redirect('showlist',array(),2,'分配权限失败');
            }
        } else {
            $info = $role->find($roleid);
            $have_auth = explode(',', $info['role_auth_ids']);
            $auth_infoA = D('Auth')->where('auth_level=0')->select();
            $auth_infoB = D('Auth')->where('auth_level=1')->select();
            $this->assign('have_auth',$have_auth);
            $this->assign('auth_infoA',$auth_infoA);
            $this->assign('auth_infoB',$auth_infoB);
            $this->assign('info',$info);
            dump($have_auth);
            $this->display();
        }
        
    }
}